package br.com.vti.leilao.model.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author ednardomatos
 */
@Entity
@Table(name = "t_lance", catalog = "homologacao", schema = "leilao")
@SequenceGenerator(name = "seq_lance", sequenceName = "leilao.seq_lance", initialValue = 1, allocationSize = 1)
public class Lance implements Serializable, Model<Integer> {
    
    private static final long serialVersionUID = -4815670712683710787L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_lance")
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    
    @Basic(optional = false)
    @Column(name = "vlr_lance")
    private Double vlrLance;
    
    @Basic(optional = false)
    @Column(name = "hora_lance", insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date horaLance;
    
    @JoinColumn(name = "usuario_fk", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Usuario usuarioFk;
    
    @JoinColumn(name = "leilao_fk", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private Leilao leilaoFk;

    public Lance() {
    }

    public Lance(Double vlrLance, Usuario usuarioFk, Leilao leilaoFk) {
        this.vlrLance = vlrLance;
        this.usuarioFk = usuarioFk;
        this.leilaoFk = leilaoFk;
    }

    @Override
    public Integer getId() {
        return id;
    }

    @Override
    public void setId(Integer id) {
        this.id = id;
    }

    public Double getVlrLance() {
        return vlrLance;
    }

    public void setVlrLance(Double vlrLance) {
        this.vlrLance = vlrLance;
    }

    public Date getHoraLance() {
        return horaLance;
    }

    public void setHoraLance(Date horaLance) {
        this.horaLance = horaLance;
    }

    public Usuario getUsuarioFk() {
        return usuarioFk;
    }

    public void setUsuarioFk(Usuario usuarioFk) {
        this.usuarioFk = usuarioFk;
    }

    public Leilao getLeilaoFk() {
        return leilaoFk;
    }

    public void setLeilaoFk(Leilao leilaoFk) {
        this.leilaoFk = leilaoFk;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 29 * hash + (this.vlrLance != null ? this.vlrLance.hashCode() : 0);
        hash = 29 * hash + (this.usuarioFk != null ? this.usuarioFk.hashCode() : 0);
        hash = 29 * hash + (this.leilaoFk != null ? this.leilaoFk.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Lance other = (Lance) obj;
        if (this.vlrLance != other.getVlrLance() && (this.vlrLance == null || !this.vlrLance.equals(other.getVlrLance()))) {
            return false;
        }
        if (this.usuarioFk != other.getUsuarioFk() && (this.usuarioFk == null || !this.usuarioFk.equals(other.getUsuarioFk()))) {
            return false;
        }
        if (this.leilaoFk != other.getLeilaoFk() && (this.leilaoFk == null || !this.leilaoFk.equals(other.getLeilaoFk()))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Lance{" + "vlrLance=" + vlrLance + ", horaLance=" + horaLance + ", usuarioFk=" + usuarioFk + ", leilaoFk=" + leilaoFk + "}";
    }

}
